package com.eshopkeeper.web.sys;


import com.eshopkeeper.core.base.BaseSysController;
import com.eshopkeeper.core.util.WebUtil;
import com.eshopkeeper.model.sys.SysMenu;
import com.eshopkeeper.service.sys.SysMenuBtnService;
import com.eshopkeeper.service.sys.SysMenuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * Created by Administrator on 2017/8/30.
 */@RestController
@Api(value = "菜单按钮管理", description = "菜单按钮管理")
@RequestMapping(value = "menubtn", method = RequestMethod.POST)
public class SysMenuBtnController extends BaseSysController {
    @Autowired
    private SysMenuBtnService sysMenuBtnService;
    @Autowired
    private SysMenuService sysMenuService;
    // 查询菜单
    @ApiOperation(value = "查询菜单按钮")
    /*//@RequiresPermissions("sys.menu.read")*/
    @RequestMapping(value = "/read/list")
    public Object get(HttpServletRequest request, ModelMap modelMap) {
        Map<String, Object> params = WebUtil.getParameterMap(request);
        List<Map<String,Object>> list=sysMenuBtnService.queryMenuBtnList(params);
        SysMenu sysMenu=sysMenuService.queryById(Long.parseLong(params.get("menuId").toString()));
        Map<String,Object> resultMap=new HashMap<>();
        resultMap.put("list",list);
        resultMap.put("sysMenu",sysMenu);
        return setSuccessModelMap(modelMap, resultMap);
    }


    // 新增菜单按钮信息
    @ApiOperation(value = "添加菜单按钮")
    /*//@RequiresPermissions("sys.menu.add")*/
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    public Object add(HttpServletRequest request, ModelMap modelMap) {
        Map<String, Object> params = WebUtil.getParameterMap(request);
        sysMenuBtnService.insertBtn(params);
        return setSuccessModelMap(modelMap);
    }

    // 修改菜单
    @ApiOperation(value = "修改菜单按钮信息")
    /*//@RequiresPermissions("sys.menu.update")*/
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public Object update(HttpServletRequest request, ModelMap modelMap) {
        Map<String, Object> params = WebUtil.getParameterMap(request);
        sysMenuBtnService.updateBtn(params);
        return setSuccessModelMap(modelMap);
    }
    // 修改菜单
    @ApiOperation(value = "启用或者禁用菜单按钮信息")
    /*//@RequiresPermissions("sys.menu.update")*/
    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    public Object delete(HttpServletRequest request, ModelMap modelMap) {
        Map<String, Object> params = WebUtil.getParameterMap(request);
        sysMenuBtnService.deleteBtn(params);
        return setSuccessModelMap(modelMap);
    }


}
